home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 51
/
Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso
/
-in_the_mag-
/
pdselect
/
awnp
/
awnp-docs
/
demos
/
xo.rx
< prev
next >
Wrap
Text File
|
2000-02-16
|
4KB
|
147 lines
/* X and O Board Demo of AWNPipe: gui image handling.
This script demonstrates how to define, use, and replace button images.
The image file is only loaded once when the first button is created.
The other buttons reuse the previous BUTTON bitmap since no file name is
given. Image definitions use image buffer 0 since this is where the
rootbitmap for buttons is stored. */
/* define the gui*/
call setup()
do while 1 /* forever*/
/* reset board logic*/
winner=0
do i=2 for 11
key.i=0
end
/*open the gui*/
call open(ca,'awnpipe:/xc')
call writeln(ca,gui'open')
/*Main loop finishes with a leave command*/
/*i counts the number of moves made.*/
i=0
do while 1
/* start event stream */
call writeln(ca,'con')
/* read an event and parse it*/
in=readln(ca)
parse value in with in1 in2 in3
/* quit if windw is closed*/
if in1='close' then exit
/* handle gadget hits*/
if in1='gadget' then do
/*restart gadget...leave the main loop (back to forever loop)*/
if in2=13 then leave
/* rest are board buttons ignore if we have a winner*/
else if winner=0 then do
call make(in2)
/*no need to check for a winner before 5 moves*/
if i>4 then call checkwin()
/* have we used all the spaces and not got a winner ?*/
if ((i>8)&(winner=0)) then do
/* set windw title and add restart button*/
winner=3
call writeln(ca,'id 0 s 8 gt "Nobody Wins!"')
writeln(ca,'define Button gt "Restart Game"')
writeln(ca,'ref')
end
end
end
end
/*close the gui , then loop back for new game */
call close(ca)
end
exit/* we should never get to here...*/
make:
i=i+1
/* make an x or o image and set board logic*/
if bittst(i,0) then call makex(arg(1))
else call makeo(arg(1))
/* set the image in the proper button and disable button*/
call writeln(ca,'id 'arg(1)' ni 0 ro 1')
return(0)
makex:
/* make an image and set board logic*/
call writeln(ca,'define bitmap trans anim 0|0|70|51|0|0|0 ' )
key.in2=1
return(0)
makeo:
/* make an image and set board logic*/
call writeln(ca,'define bitmap trans anim 74|0|70|51|0|0|0 ' )
key.in2=10
return(0)
checkwin:
if key.7~=0 then do
if ((key.7= key.6 & key.7=key.8) |(key.7= key.3 & key.7=key.11 ) | (key.7= key.2 & key.7=key.12 ) | (key.7= key.4 & key.7=key.10)) then call win(7)
end
if key.2~=0 then do
if ((key.2= key.3 & key.2=key.4) | (key.2= key.6 & key.2=key.10)) then call win(2)
end
if key.12~=0 then do
if ((key.12= key.11 & key.12=key.10) | (key.12= key.4 & key.12=key.8)) then call win(12)
end
return
win:
parse arg winner
/*set windw title to show winner*/
if key.winner=1 then call writeln(ca,'id 0 s 8 gt "X Wins!"')
else call writeln(ca,'id 0 s 8 gt "O Wins!"')
return(1)
setup:
/* layouts have a Gadget ID so the buttons are
2 | 3| 4
--------
6 | 7| 8
--------
10|11|12
restart is 13 when added*/
/* easy layout control*/
le='le'||'0a'x
lo='layout b 0'||'0a'x
/* windw definition sets quiet flag since we know what our GIDs will be*/
/* modify is turned on so we can modify the GUI*/
gui='" X and O Demo" cg dg db v m q fw fh'||'0a'x
/* first button loads an image (reused by all other graphics)*/
gui=gui||lo||'button b 0 trans fn "xo.gif" anim 150|0|70|51|0|0|0'||'0a'x
/*a blank button, verticle, and horizontal line*/
blank='button b 0 trans anim 150|0|70|51|0|0|0'||'0a'x
vertline='bitmap part 71|0|3|51|0|0|0'||'0a'x||'image'||'0a'x
horzline='bitmap part 0|52|216|3|0|0|0'||'0a'x||'image'||'0a'x
/*build the rest of the board*/
gui=gui||vertline||blank||vertline||blank||le||horzline
gui=gui||lo||blank||vertline||blank||vertline||blank||le||horzline
gui=gui||lo||blank||vertline||blank||vertline||blank||le
gui=gui||'define Button gt "Restart Game"'||le
return